{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f37f766f",
   "metadata": {},
   "outputs": [],
   "source": [
    "##1.随机函数\n",
    ">1.random.random():生成随机数\n",
    ">2.random.randint():生成随机数\n",
    ">3.random.choices():随机抽样"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "36c9b17d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "27275d18",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function random:\n",
      "\n",
      "random() method of random.Random instance\n",
      "    random() -> x in the interval [0, 1).\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(random.random)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "880305c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8027322957647403"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ec5e2049",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method randint in module random:\n",
      "\n",
      "randint(a, b) method of random.Random instance\n",
      "    Return random integer in range [a, b], including both end points.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(random.randint) #整数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "37c94ded",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.randint(0,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a2713f0c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "1\n",
      "2\n",
      "1\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "#random 小实践 大话骰\n",
    "for i in range (5):\n",
    "     print( random.randint(0,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f76c9d7a",
   "metadata": {},
   "outputs": [],
   "source": [
    "#random 小实践 猜数字 0-100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0fceb7dd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Xiaoming']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#random.choices()，在数据组（列表）随机选择一个值\n",
    "random.choices([\"Alex\",\"Xiaoming\",\"Lihua\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "e18067e8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "41\n",
      "64\n",
      "88\n",
      "35\n",
      "32\n",
      "8\n"
     ]
    }
   ],
   "source": [
    "#通过随机值，大概去判断一下彩票的中间概率\n",
    "#[12,34,65,10,22,12]\n",
    "for i in range (6):\n",
    "     print( random.randint(0,99))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cfcd9ff6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
